package org.jeecg.modules.iot.mqtt.server.service.processor;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class JT808MessageGeneratorFactory {
    private static final Map<String, JT808MessageGenerator> generators = new HashMap<>();

   /* @Autowired
    public JT808MessageGeneratorFactory(List<JT808MessageGenerator> strategies) {
        for (JT808MessageGenerator strategy : strategies) {
            generators.put(strategy.getType(), strategy);
        }
    }

    public static JT808MessageGenerator getGenerator(String type) {
        return generators.get(type);
    }*/



    @Autowired
    private List<JT808MessageGenerator> strategies;

    @PostConstruct
    public void init() {
        for (JT808MessageGenerator strategy : strategies) {
            generators.put(strategy.getType(), strategy);
        }
    }

    public JT808MessageGenerator getGenerator(String type) {
        return generators.get(type);
    }


    public JT808MessageGenerator createGenerator(MessageType type) {
        return generators.get(type);
    }
}
